1. Field of the Invention
The present invention generally relates to a method for accessing image data, and more particularly to a method which requires only one buffer for instantly compressing JPEG image data.
2. Description of Related Art
Generally, charge coupled devices (CCDs) and complementary metal-oxide semiconductors (CMOSs) are often used as sensors for conventional digital cameras or cellular phone cameras. Such sensors typically output images with a line based raster scan module. However, when using a JPEG format image data compressing method, because of the block base used therein, e.g., compressing image data in a way of taking 8×8 pixels as a block for scanning, there needs an extra procedure for transferring the image data arrangement inserted between processes of the sensor outputting the image data and compressing the data in accordance with the JPEG format.
FIG. 1 illustrates a flowchart of a JPEG code transformation. Referring to FIG. 1, before finally obtaining compressed bitstream and further achieving the JPEG code transformation, the image data must be processed by steps including: step 101, color transfer; step 102, discrete cosine transfer; step 103, quantization; and step 104, encoding. However, because the image data have to be processed by the discrete cosine transfer step 102, the JPEG image data must be encoded in minimum coded unit (MCU) so as to achieve compressed bitstream wherein each MCU is a sub-image of 8×8 pixels.
When the image data are compressed with YUV420 compression format defined by JPEG, because of the definition of the YUV420 compression format, the image data are divided into many sub-blocks for JPEG compression.
FIG. 2 is a schematic diagram for illustrating the definition of the YUV420 compression format. As illustrated by FIG. 2, the YUV420 compression format is to obtain four Y component blocks of 8×8 pixels, one U component block of 8×8 pixels, and one V component blocks of 8×8 pixels from each image block of 16×16 pixels of the image data, wherein each image block does not overlap another image block. The Y component represents brightness of a pixel, while the U component and the V component represent a color tone and a color saturation of a pixel respectively. The sequence of the discrete cosine transfer process is Y11, Y12, Y21, Y22, U1, and V1 as illustrated in FIG. 2. Therefore, the YUV420 compression must be performed based on data of 16 lines to compress the JPEG image data.
Conventionally, a two-buffer structure, e.g., an A/B buffer structure, is often employed to convert arrangement of image data between line base and block base (MCU block). The foregoing A/B buffer structure is that when the image is being written into the A buffer, a JPEG engine obtains data from the B buffer for compression, and while the image data is being written into the B buffer, the JPEG engine obtains data from the A buffer for compression. When using an A/B buffer structure for processing a YUV420 compression, all buffer size needed thereby are 32 lines, which means a storage space defined by the 32 lines in the buffers.
FIG. 3 is a schematic diagram for illustrating a conventional A/B buffer structure. As shown in FIG. 3, the A buffer 301 and the B buffer 302 are both 16-line buffers. In such a structure, a user may use a switch 303 for determining to input image data of the raster scan sequence to the A buffer 301 or the B buffer 302, and use a switch 304 for determining to output pixel block data stored in the A buffer 301 or the B buffer 302. The user may also use vertical synchronous signals, horizontal synchronous signals, and clock signals to either have a writing address controller 305 to drive the A buffer 301 or the B buffer 302 to conduct a writing action of the image data of the raster scan sequence, or have a reading address controller 306 to drive the A buffer 301 or the B buffer 302 to conduct a reading action, i.e., outputting, of the pixel block image data.
Although, the A/B buffer structure can achieve instant JPEG compression, when applied in digital cameras or mobile communication, it is to be avoided to consume excessive power, and therefore a static random access memory (SRAM) must be used for storing the A/B buffer data. Unfortunately, doing so wastes precious SRAM resources. Taking a 1.3M sensor for example, a 12-line buffer requires about 30 Kbit SRAM, which is about 14% die cost of the entire chip. Accordingly, using the least buffers to achieve instant JPEG compression is a major concern currently for most manufacturers.
Besides, as to the design of the buffers themselves, because image data are input into the buffers (reading image data) and output from the buffer (writing image data) in different ways, the user must use such an A/B buffer structure. Therefore, when conducting a YUV420 compression, because of the JPEG definition, only after data of all 16 lines are read to the buffer (ready status), the compression can be conducted. In such a way, the JPEG compression is only to some degree instantly compressed when using the A/B buffer structure.
FIG. 4 is a schematic diagram for illustrating an image data of 640×480 pixels that is line base and after being YUV420 sampled. FIG. 5(a) is a schematic diagram for illustrating inputting image data to a 12-line buffer. FIG. 5(b) is a schematic diagram for illustrating outputting image data from a 12-line buffer. The image data of 640×480 pixels indicate a horizontal resolution of 640 pixels and a vertical resolution of 480 pixels of the image data. As shown in FIG. 4, the image data contain 480 lines of data, respectively line 1 through line 480. Because the image data of the 640×480 pixels as shown in FIG. 4 have been YUV420 sampled, therefore each line data presented in FIG. 4 and marked with odd numbers have a Y component, a U component and a V component, while each line data presented in FIG. 4 and marked with even numbers have only a Y component. FIGS. 5(a) and 5(b) illustrate buffers having storage spaces L1 through L16, each block in the storage spaces, such as the memory cell 501 and the half memory cell 502 shown in FIG. 5(a), and the memory cell 503 and the half memory cell 504 as shown in FIG. 5(b), can temporally store data of 8 pixels.
Line data 1 through 16 are written in sequence into the storage spaces L1 through L16. When all storage spaces in the buffer are filled by the image data, the JPEG engine starts to obtain the data therefrom in a way as shown as 505 in FIG. 5 to obtain data from data cells marked with 1 and 2 in storage spaces L1 through L16. Then the JPEG engine according to the way as illustrated by 505 obtains data from data cells marked with 3 and 4 in storage spaces L1 through L16. Likewise, data written in data cells marked with 5 through 80 in storage spaces L1 through L16 are obtained in similar way. Similarly as the foregoing description of line data 1 through 16, the buffer, the JPEG engine further temporarily store the line data 17 through 32, 33 through 48, 49 through 64, . . . , into the buffer till the line data 465 through 480 are output from the buffer. However, according to such an operation method, the line data 33 through 48 can be input into the buffer only after all line data 17 through 32 have been output from the buffer, which consumes a lot of time and limit the degree of instant JPEG compression. Similarly, the line data 33 through 48 can be input into the buffer only after all line data 17 through 32 have been output therefrom. As such, convention operation wastes a lot of time in waiting.
Furthermore, it can be learned from FIGS. 5(a) and 5(b), although the storage spaces are marked with L1 through L16, the storage spaces L2, L4, L6, L8, L10, L12, L14, and L16 store only Y component therein, so that the storage volume of storage spaces L2 and L4 are equivalent to any one of the storage spaces L1, L3, L5, L7, L9, L11, L13 and L15. Storage spaces L6 and L8, L10 and L12, L14 and L16 are similar to L2 and L4 as discussed above. Accordingly, the conventional technology requires a 24-line buffer, that is an A/B buffer, each of the A buffer and the B buffer has 12 lines, for instant JPEG compression in accordance with the features of reading/writing different SRAMs. As such, the conventional technology has relatively high production cost when adopting A/B buffer structures.